package cn.xuewenbao.ucenter.mapper;

import cn.xuewenbao.ucenter.entity.Follow;
import cn.xuewenbao.ucenter.entity.vo.FollowVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 关注表 Mapper 接口
 * </p>
 *
 * @author mafayu
 * @since 2021-04-19
 */
@Mapper
public interface FollowMapper extends BaseMapper<Follow> {
    @Select("SELECT f.id id, f.followed_user_id followedUserId, mb.username followedUserName, mdb.fan_count followedUserFanCount, mb.avatar followedUserAvatar, (SELECT COUNT(1) FROM follow f2 where f2.user_id = f.followed_user_id AND f2.followed_user_id = f.user_id)>0 isFollowMutually\n" +
            "FROM follow AS f \n" +
            "LEFT JOIN member AS mb ON f.followed_user_id = mb.id \n" +
            "LEFT JOIN member_data AS mdb ON f.followed_user_id = mdb.user_id\n" +
            "WHERE f.user_id = #{userId} ;")
    List<FollowVo> getFolloweeInfo(String userId);

    @Select("SELECT f.id id, f.user_id userId, ma.username userName, mda.fan_count userFanCount, ma.avatar userAvatar, (SELECT COUNT(1) FROM follow f2 where f2.user_id = f.followed_user_id AND f2.followed_user_id = f.user_id)>0 isFollowMutually\n" +
            "FROM follow AS f \n" +
            "LEFT JOIN member AS ma ON f.user_id = ma.id\n" +
            "LEFT JOIN member_data AS mda ON f.user_id = mda.user_id\n" +
            "WHERE f.followed_user_id = #{userId} ;")
    List<FollowVo> getFanInfo(String userId);
}
